package cn.com.xjnt.vas.ordering.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.frameworks.core.repository.BaseRepository;
import com.frameworks.core.service.AbstractBaseService;

import cn.com.xjnt.vas.manage.domain.entity.Account;
import cn.com.xjnt.vas.ordering.domain.entity.Hospital;
import cn.com.xjnt.vas.ordering.domain.entity.News;
import cn.com.xjnt.vas.ordering.repository.NewsRepository;
import cn.com.xjnt.vas.ordering.service.NewsService;

/** 
* 类说明：
* @author 作者 LUXIN
* @version 创建时间：2016年5月11日15:59:51
*/
@Service
@Transactional
public class NewsServiceImpl extends AbstractBaseService<News, Long> implements NewsService {
    @Autowired
    private NewsRepository newsRepository;
    
    @Override
    protected BaseRepository<News, Long> getBaseRepository() {
        return newsRepository;
    }

    @Override
    public void save(News entity) {
        super.saveOrUpdate(entity);
    }

    @Override
    public void update(News entity) {
        super.saveOrUpdate(entity);
    }

    @Override
    public void publishById(Long id,Account model) {
       News news = newsRepository.findOne(id); 
       news.setStatus(1);
       news.setPublisher(model.getRealname());
       news.setPublishTime(new Date());
       super.saveOrUpdate(news);
    }

    @Override
    public void publishByIds(Long[] ids,Account model) {
        for (Long id : ids) {
            News news = newsRepository.findOne(id); 
            news.setStatus(1);
            news.setPublisher(model.getRealname());
            news.setPublishTime(new Date());
            super.saveOrUpdate(news);
        }
    }

    @Override
    public List<News> findByHospital(Hospital hospital) {
        return newsRepository.findByHospital(hospital);
    }
}
 